`timescale 1ns/1ps

module max_filer_custom_tb;
////////////////////////////////////////////////////////////////////////////////
parameter   KERNERL_SIZE = 5;
parameter   COL = 192;
parameter   ROW = 108;
reg clk,rst_n,rst_tb_n;
initial begin 
    clk = 0;
    rst_n = 0;
    rst_tb_n = 0;
    #200;
    rst_n = 1;
    #1000;
    rst_tb_n = 1;
end 
always #5 clk = ~clk;
////////////////////////////////////////////////////////////////////////////////
reg s_axis_tvald;
reg [7:0] s_axis_tdata;
wire m_axis_tvald;
wire [7:0] m_axis_tdata;

reg [15:0] col_cnt;
reg [15:0] row_cnt;

always @ (posedge clk,negedge rst_tb_n)
begin 
    if (!rst_tb_n) begin 
        col_cnt <= 'd0;
    end
    else if (col_cnt >= COL+COL/8) begin 
        col_cnt <= 'd0;
    end 
    else begin 
        col_cnt <= col_cnt + 1'd1;
    end 
end 

always @ (posedge clk,negedge rst_tb_n)
begin 
    if (!rst_tb_n) begin 
        row_cnt <= 'd0;
    end 
    else if (col_cnt == COL+COL/8) begin 
        if (row_cnt == ROW-1) begin 
            row_cnt <= 'd0;
        end 
        else begin 
            row_cnt <= row_cnt + 1'd1;
        end 
    end 
    else begin 
        row_cnt <= row_cnt;
    end 
end 

always @ (posedge clk,negedge rst_tb_n)
begin 
    if (!rst_tb_n) begin 
        s_axis_tvald <= 1'd0;
        s_axis_tdata <= 'd0;
    end 
    else if (col_cnt >= 1 && col_cnt <= COL) begin 
        case (col_cnt) 
        'd1: begin 
            s_axis_tvald <= 1'd1;
            s_axis_tdata <= row_cnt + 1'd1;
            end 
        default: begin 
            s_axis_tvald <= 1'd1;
            s_axis_tdata <= s_axis_tdata + 1'd1;
            end 
        endcase 
    end 
    else begin 
        s_axis_tvald <= 1'd0;
        s_axis_tdata <= 'd0;
    end 
end 
////////////////////////////////////////////////////////////////////////////////
max_filer_custom # 
( 
    .KERNERL_SIZE   ( KERNERL_SIZE  ),
    .COL            ( COL           ),
    .ROW            ( ROW           )
) max_filer_custom_inst 
(
    .clk             ( clk ), // input       wire            
    .rst_n           ( rst_n ), // input       wire            
    .s_axis_tvald    ( s_axis_tvald ), // input       wire            
    .s_axis_tdata    ( s_axis_tdata ), // input       wire    [7:0]   
    .m_axis_tvald    ( m_axis_tvald ), // output      wire            
    .m_axis_tdata    ( m_axis_tdata )  // output      wire    [7:0]   
);

endmodule 
